from PySide6.QtWidgets import (
    QWidget,
    QLabel,
    QLineEdit,
    QPushButton,
    QVBoxLayout,
    QHBoxLayout,
)


# 党费计算器
class PartyFeeCalculator(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("Party Fee Calculator")
        self.setObjectName("党委计算器")

        self.label_name = QLabel("税后收入：")
        self.input_box = QLineEdit()
        self.input_box.setPlaceholderText("人民币")
        self.button_compute = QPushButton("计算")
        self.button_clear = QPushButton("清除")

        layout = QVBoxLayout()

        m_layout = QHBoxLayout()
        m_layout.addWidget(self.label_name)
        m_layout.addWidget(self.input_box)

        bt_layout = QHBoxLayout()
        bt_layout.addWidget(self.button_compute)
        bt_layout.addWidget(self.button_clear)

        layout.addLayout(m_layout)
        layout.addLayout(bt_layout)

        self.setLayout(layout)

        self.button_compute.clicked.connect(self.compute)
        self.button_clear.clicked.connect(self.clear)

    def compute(self):
        """

        :return:
        """
        try:
            recv = self.__compute(float(self.input_box.text()))
            print(recv)
        except ValueError:
            pass

    @staticmethod
    def __compute(revenue: int | float):
        """
        0 - 3000  0.5%
        3000 - 5000  1%
        5000 - 10000  1.5%
        10000 以上   2%
        :return:
        """
        __sun = 0
        match revenue:
            case x if x <= 3000:
                __sun = x * 0.005
            case x if x <= 5000:
                __sun = PartyFeeCalculator.__compute(3000) + (x - 3000) * 0.01
            case x if x <= 10000:
                __sun = PartyFeeCalculator.__compute(5000) + (x - 5000) * 0.015
            case x if x > 10000:
                __sun = PartyFeeCalculator.__compute(10000) + (x - 10000) * 0.02

        return __sun

    def clear(self):
        self.input_box.clear()
